package com.dofast.bt.mvp.view.activity.my;

import android.os.Bundle;
import android.support.v4.content.Loader;
import android.view.View;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.TextView;

import com.dofast.bt.R;
import com.dofast.bt.base.BaseMvpActivity;
import com.dofast.bt.mvp.presenter.my.CollectStoreListPresenter;
import com.dofast.bt.mvp.view.activity.basket.StoreDetailActivity;
import com.dofast.bt.mvp.view.activity.message.WebViewActivity;
import com.dofast.bt.util.PresenterFactory;
import com.dofast.bt.util.PresenterLoder;
import com.dofast.bt.widget.MyDeleteListView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * username:Created by hsj on 2016/12/22 0022.
 * class：
 * 类描述：收藏店铺列表
 */

public class CollectStoreListActivity extends BaseMvpActivity<CollectStoreListPresenter, CollectStoreListView> implements CollectStoreListView, AdapterView.OnItemClickListener {
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_edit)
    TextView tvEdit;
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_empty)
    TextView tvEmpty;
    @BindView(R.id.listview)
    MyDeleteListView listview;

    @Override
    protected int getResourcesId() {
        return R.layout.activity_collect_store_list;
    }

    @Override
    protected void initView() {
        initTitle();
        presenter.initData();
    }

    @Override
    protected void addOnClickListener() {
        listview.setOnItemClickListener(this);
        listview.setDelButtonClickListener(new MyDeleteListView.DelButtonClickListener() {
            @Override
            public void clickHappend(int position) {
                presenter.delete(position);
            }
        });
    }

    @Override
    public Loader<CollectStoreListPresenter> onCreateLoader(int id, Bundle args) {
        return new PresenterLoder<>(this, new PresenterFactory<CollectStoreListPresenter>() {
            @Override
            public CollectStoreListPresenter create() {
                return new CollectStoreListPresenter();
            }
        });
    }

    @Override
    public void initAdapter(Adapter adapter) {
        listview.setAdapter((ListAdapter) adapter);

    }

    @Override
    public void showDetail(int shopId) {
        StoreDetailActivity.goTo(this, shopId);
    }

    @Override
    public boolean isCollectWord() {
        return getIntent().getBooleanExtra("hot", false);
    }

    @Override
    public void setTitle(String title) {
        tvTitle.setText(title);
    }

    @Override
    public void gotoWeb(String url) {
        WebViewActivity.gotoWeb(CollectStoreListActivity.this, url);
    }

    @Override
    public void showEmpty() {
        tvEmpty.setVisibility(View.VISIBLE);
    }

    @Override
    public void hideEmpty() {
        tvEmpty.setVisibility(View.GONE);
    }

    @Override
    public void initTitle() {
        tvTitle.setText("收藏的店铺");
        ivBack.setVisibility(View.VISIBLE);
        tvEdit.setVisibility(View.GONE);
    }

    @Override
    public void gotoActivity(Class<?> tClass, boolean isFinish) {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick(R.id.iv_back)
    public void onClick() {
        finish();
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        presenter.itemClick(position);
    }
}
